package com.jsh.erp.service.gongxu;

import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.service.person.PersonResource;
import com.jsh.erp.service.person.PersonService;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Service(value = "gongxu_component")
@GongxuResource
public class GongxuComponent implements ICommonQuery {

    @Resource
    private GongxuService gongxuService;

    @Override
    public Object selectOne(Long id) throws Exception {
        return gongxuService.getGongxu(id);
    }

    @Override
    public List<?> select(Map<String, String> map,HttpServletRequest request)throws Exception {
        return getPersonList(map,request);
    }

    private List<?> getPersonList(Map<String, String> map,HttpServletRequest request) throws Exception{
        String search = map.get(Constants.SEARCH);
        String name = StringUtil.getInfo(search, "name");
        String order = QueryUtils.order(map);
        return gongxuService.select(name, QueryUtils.offset(map), QueryUtils.rows(map));
    }

    @Override
    public Long counts(Map<String, String> map,HttpServletRequest request) throws Exception{
        String search = map.get(Constants.SEARCH);
        String name = StringUtil.getInfo(search, "name");
        return gongxuService.countGongxu(name);
    }

    @Override
    public int insert(String beanJson, HttpServletRequest request)throws Exception {
        return gongxuService.insert(beanJson, request);
    }

    @Override
    public int update(String beanJson, Long id, HttpServletRequest request)throws Exception {
        return gongxuService.update(beanJson, id, request);
    }

    @Override
    public int delete(Long id, HttpServletRequest request)throws Exception {
        return gongxuService.delete(id, request);
    }

    @Override
    public int batchDelete(String ids, HttpServletRequest request)throws Exception {
        return gongxuService.batchDelete(ids, request);
    }

    @Override
    public int checkIsNameExist(Long id, String name)throws Exception {
        return gongxuService.checkIsNameExist(id, name);
    }

}
